package com.estore.service;

import com.estore.model.Product;
import java.util.Comparator;

<<<<<<< HEAD
public class ProductSorters {
    // 按商品价格从低到高排序（升序）
    public static final Comparator<Product> BY_PRICE_ASC =
            Comparator.comparingDouble(Product::getPrice);

    // 按商品价格从高到低排序（降序）
    public static final Comparator<Product> BY_PRICE_DESC =
            Comparator.comparingDouble(Product::getPrice).reversed();

    // 按商品库存从多到少排序（降序）
    public static final Comparator<Product> BY_STOCK_DESC =
            Comparator.comparingInt(Product::getStock).reversed();
}

=======
/**
 * 商品排序器工具类
 * 提供多种商品排序规则的比较器
 */
public class ProductSorters {

    /**
     * 按商品价格从低到高排序
     */
    public static final Comparator<Product> BY_PRICE_ASC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Double.compare(p1.getPrice(), p2.getPrice());
        }
    };

    /**
     * 按商品价格从高到低排序
     */
    public static final Comparator<Product> BY_PRICE_DESC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Double.compare(p2.getPrice(), p1.getPrice());
        }
    };

    /**
     * 按商品库存从多到少排序
     */
    public static final Comparator<Product> BY_STOCK_DESC = new Comparator<Product>() {
        @Override
        public int compare(Product p1, Product p2) {
            return Integer.compare(p2.getStock(), p1.getStock());
        }
    };
}
>>>>>>> a021c18158922de0cb3f60df6501b6d404563760
